<?php

namespace Cktadmin\Controller;

use Common\Controller\BasicAdmin;
use Common\Service\DataService;

class PackageController extends BasicAdmin {

    public $table = 'package';

    public function index() {
        $this->title = '套餐管理';
        $where = array();
        $get = I('get.');
        (isset($get['key']) && $get['key'] !== '') && $where['name|description'] = array('like', "%{$get['key']}%");
//        $count = M($this->table)->where($where)->count();
        $db = M($this->table)->where($where)->order('sort asc,id desc');
        return parent::_list($db);
    }

    public function add() {
        return parent::_form($this->table, 'form');
    }

    public function edit() {
        return parent::_form($this->table, 'form');
    }

    public function _add_form_filter(&$vo) {
        if (IS_POST) {
            $vo['add_time'] = time();
        }
    }

    public function del() {
        if (DataService::update($this->table)) {
            $this->success('删除成功！');
        }
        $this->error('删除失败！');
    }

}
